/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.ShipperProcessor;

import com.sun.Entity.Invoicefordelaypenalty;
import com.sun.Facade.InvoicefordelaypenaltyFacadeLocal;
import com.sun.Facade.ShippingorderFacadeLocal;
import exceptions.AmountNotCorrespondingException;
import exceptions.UnknownOrderException;
import exceptions.UnknownPenalityInvoiceException;
import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ejb.Stateless;

/**
 *
 * @author test
 */
@WebService()
@Stateless()
public class ReceiveInvoicePaymentWS {

    @EJB
    private InvoicefordelaypenaltyFacadeLocal invoicefordelaypenaltyFacade;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "ReceiveInvoicePayment")
    public void ReceiveInvoicePayment(
            @WebParam(name = "PInvoiceID") String PInvoiceID,
            @WebParam(name = "OrderID") String OrderID,
            @WebParam(name = "Amount") Float Amount)
            throws
            UnknownOrderException,
            UnknownPenalityInvoiceException,
            AmountNotCorrespondingException {

        // Verification PInvoiceID existance
        Invoicefordelaypenalty PInvoice = invoicefordelaypenaltyFacade.find(PInvoiceID);
        if (PInvoice == null) {
            throw new UnknownOrderException();
        }

        // Verificate valid amount
        if (Amount != PInvoice.getAmount()) {
            throw new AmountNotCorrespondingException();
        }

        PInvoice.setIspaid(1);
        invoicefordelaypenaltyFacade.edit(PInvoice);
    }
}
